<?php
/**
*
* @package phpBB3
* @version $Id$
* @copyright (c) 2005 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/

/**
*/

/**
* @ignore
*/
 
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include_once($phpbb_root_path . 'common.' . $phpEx);
include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
include_once($phpbb_root_path . 'sv_common.' . $phpEx);
include_once($phpbb_root_path . 'ofc/php-ofc-library/open-flash-chart.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('stockvirtual');

$money = $user->data['user_money'];
$user_id 	= $user->data['user_id'];

if ($user_id == ANONYMOUS)
{
	login_box();
}
if ($auth->acl_getf_global('m_') == false)
{
	// no enough priviledge, return.
	login_box();
}

// Basic parameter data
$mode		= request_var('mode', '');

if ($mode == 'add_equity_change')
{
	$corp_id				= request_var('corp_id', '');
	$share_unit				= request_var('share_unit', '');
	$cash_after_change		= request_var('cash_after_change', '');
	$corp_id_after_change	= request_var('corp_id_after_change', '');
	$share_after_change		= request_var('share_after_change', '');
	$corp_id_after_change_2	= request_var('corp_id_after_change_2', '');
	$share_after_change_2	= request_var('share_after_change_2', '');
	$corp_id_after_change_3	= request_var('corp_id_after_change_3', '');
	$share_after_change_3	= request_var('share_after_change_3', '');
	$scheduled_date			= request_var('scheduled_date', '');

	if ($corp_id_after_change == "")
		$share_after_change = 0;
	if ($corp_id_after_change_2 == "")
		$share_after_change_2 = 0;
	if ($corp_id_after_change_3 == "")
		$share_after_change_3 = 0;
		
	if (is_valid_corp_id($corp_id) && $share_unit > 0 && $scheduled_date != "")
	{
		$sql = 'INSERT INTO sv_equity_change_event (corp_id, share_unit, cash_after_change, corp_id_after_change, share_after_change, corp_id_after_change_2, share_after_change_2, corp_id_after_change_3, share_after_change_3, scheduled_date) VALUES ("' . $corp_id . '" ,' . $share_unit . ' , ' . $cash_after_change . ', "' . $corp_id_after_change . '", ' . $share_after_change . ', "' . $corp_id_after_change_2 . '", ' . $share_after_change_2 . ', "' . $corp_id_after_change_3 . '", ' . $share_after_change_3 . ', "' . $scheduled_date . '")';
		$result = $db->sql_query($sql);
	}
}

// list all equity change events. 
$sql 	= 'SELECT * FROM sv_equity_change_event';
$result = $db->sql_query($sql); 
while ($row = $db->sql_fetchrow($result))
{	
	// Send vars to template
	$template->assign_block_vars('event_list', array(		
		'CORP_ID'						=> $row['corp_id'],
		'CORP_NAME'						=> get_corp_chinese_name($row['corp_id']),
		'SHARE_UNIT'					=> $row['share_unit'],
		'CASH_AFTER_CHANGE'				=> $row['cash_after_change'],
		'CORP_ID_AFTER_CHANGE'			=> $row['corp_id_after_change'],
		'SHARE_AFTER_CHANGE'			=> $row['share_after_change'],
		'CORP_ID_AFTER_CHANGE_2'		=> $row['corp_id_after_change_2'],
		'SHARE_AFTER_CHANGE_2'			=> $row['share_after_change_2'],
		'CORP_ID_AFTER_CHANGE_3'		=> $row['corp_id_after_change_3'],
		'SHARE_AFTER_CHANGE_3'			=> $row['share_after_change_3'],
		'SCHEDULED_DATE'				=> $row['scheduled_date'],
		'EXECUTION_DATE'				=> $row['execution_date'],
		'STATUS'						=> $row['status'],
		)
	);
}
	

display_forums('', $config['load_moderators']);

// include nav links.
include_nav_links();

// Assign index specific vars
$template->assign_vars(array(

	'FORUM_IMG'				=> $user->img('forum_read', 'NO_NEW_POSTS'),
	'FORUM_NEW_IMG'			=> $user->img('forum_unread', 'NEW_POSTS'),
	'FORUM_LOCKED_IMG'		=> $user->img('forum_read_locked', 'NO_NEW_POSTS_LOCKED'),
	'FORUM_NEW_LOCKED_IMG'	=> $user->img('forum_unread_locked', 'NO_NEW_POSTS_LOCKED'),

	'S_LOGIN_ACTION'			=> append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login'),
	'S_DISPLAY_BIRTHDAY_LIST'	=> ($config['load_birthdays']) ? true : false,
	'U_MONEY'					=> number_format($money),
	'JASON_STRING'				=> $jason_string,
	
	
	'U_MARK_FORUMS'		=> ($user->data['is_registered'] || $config['load_anon_lastread']) ? append_sid("{$phpbb_root_path}index.$phpEx", 'hash=' . generate_link_hash('global') . '&amp;mark=forums') : '',
	'U_MCP'				=> ($auth->acl_get('m_') || $auth->acl_getf_global('m_')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main&amp;mode=front', true, $user->session_id) : '')
);

// Output page
page_header($user->lang['SV_HISTORY']);

$template->set_filenames(array(
	'body' => 'adm_equity_change.html')
);

page_footer();

?>